package com.cloudfun.campusshare.repo;

import com.cloudfun.campusshare.common.constant.AnnouncementType;
import com.cloudfun.campusshare.entity.AnnouncementEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/6/5 18:25
 * @description :
 */
public interface AnnouncementEntityRepo extends JpaRepository<AnnouncementEntity, String>, JpaSpecificationExecutor<AnnouncementEntity> {
    /**
     * 获取上线条数(运营商)
     * @param merchantId
     * @param isUsing
     * @return
     */
    Long countAllByMerchantIdAndIsUsing(String merchantId,Boolean isUsing);

    /**
     * 获取上线条数（管理员）
     * @param isUsing
     * @return
     */
    Long countAllByTypeAndIsUsing(AnnouncementType type, Boolean isUsing);



    AnnouncementEntity findByTypeAndWashPointIdAndTitleAndBeginTimeAndEndTime(AnnouncementType type,
                                                                              String washPointId,
                                                                              String title,
                                                                              LocalDateTime beginTime,
                                                                              LocalDateTime endTime);

    AnnouncementEntity findByTypeAndTitleAndBeginTimeAndEndTime(AnnouncementType type,
                                                                              String title,
                                                                              LocalDateTime beginTime,
                                                                              LocalDateTime endTime);

    List<AnnouncementEntity> findByTypeAndWashPointIdAndBeginTimeGreaterThanEqualAndEndTimeLessThanEqual(AnnouncementType type,
        String washPointId,LocalDateTime beginTime, LocalDateTime endTime);

    List<AnnouncementEntity> findByTypeAndBeginTimeGreaterThanEqualAndEndTimeLessThanEqual(AnnouncementType type,LocalDateTime beginTime, LocalDateTime endTime);

    AnnouncementEntity findByIdAndMerchantId(String id,String merchantId);


    AnnouncementEntity findByIdAndCreatorIdIn(String id, Collection<String> ids);


}
